package com.mantou.cdl.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {

	private static String reg_ip="\\d+\\.\\d+\\.\\d+\\.\\d+";
	private static String reg_host_in_url = "://(.+)/??";
	
	public static boolean isIP(String ip){
		if(NullUtil.isNull(ip))
			return false;
		return ip.matches(reg_ip);
	}
	
	public static String extractHost(String url){
		Matcher matcher = Pattern.compile(reg_host_in_url).matcher(url);
		if(matcher.find()){
			return matcher.group(1);
		}
		return null;
	}
	
	
	public static void main(String [] args){
		//System.out.println(isIP("12.46.78.76"));
		System.out.println(extractHost("http://www.baidu.com"));
	}
}
